<template>
    <div>
        <TaskProtable :teamTaskData="teamTaskData"></TaskProtable>
    </div>
</template>

<script setup>

import TaskProtable from "@/components/TaskProtable/index.vue"
import { worksData } from "@/stores/worksData.js"
import { ref, onMounted, onBeforeUnmount, getCurrentInstance, computed ,provide} from "vue"

import { staffData } from "@/stores/staff.js"
import { mainStore } from "@/stores"
let mStaff = staffData()
let mStore = mainStore()


// 提供数据给teamTask
provide("state",0)
provide("examine",0)
provide("isShowTeamName",true)

let mWorks = worksData()
let { proxy } = getCurrentInstance()

let teamTaskData = computed(() => {
    return mWorks.teamsWorksdata
})

let current = ref(1)
let take = ref(10)

// 获取团队任务中的数据
let getTeamWorksData = () => {
    let data = {
        state: 1,
        current: current.value,
        take: take.value
    }
    let res = mWorks.getWorksData(data)
}

// 获取自己团队中的员工
let getOwnTeamMember = () => {
    let obj = {
        staffId: mStore.userinfo.staffId
    }
    mStaff.getOwnteamMemberData(obj)
}



let changeCurrentPage = (e) => {
    // console.log(e,"改变了当前页")
    current.value = e
    getTeamWorksData()
}

let changeSizePage = (e) => {
    take.value = e
    current.value = 1
    getTeamWorksData()
    // console.log(e,"改变了页数")
}

// 监听刷新数据
let updateWorksData = ()=>{
    getTeamWorksData()
}


onMounted(() => {
    getOwnTeamMember()
    getTeamWorksData()
    proxy.$Bus.on("changeCurrentPage", changeCurrentPage)
    proxy.$Bus.on("changeSizePage", changeSizePage)
      // 监听刷新数据
      proxy.$Bus.on("updateWorksData",updateWorksData)

})

onBeforeUnmount(() => {
    proxy.$Bus.off("changeCurrentPage", changeCurrentPage)
    proxy.$Bus.off("changeSizePage", changeSizePage)
    proxy.$Bus.off("updateWorksData",updateWorksData)
})

</script>

<style lang="scss" scoped></style>